home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / WINDOW.ASM < prev    next >
Assembly Source File  |  1980-01-01  |  9KB  |  384 lines

  1.         name    window
  2.         page    ,132
  3.  
  4.         title    BIOS Window Extension V1.1
  5.  
  6. comment        \
  7.  
  8.         Copyright 1984 John J. Seal
  9.  
  10.         The Graphic Software Company
  11.         348 East Pratt Street
  12.         Franklin, IN 46131
  13.  
  14.         This program may be used for any non-commercial purpose
  15.         provided that this copyright notice is included.
  16.         Commercial use is forbidden without the express written
  17.         consent of The Graphic Software Company.
  18.  
  19.         This program allows a window to be defined on the display.
  20.         All programs which use the BIOS Write TTY call for output
  21.         will work within the window. Other BIOS calls may still be
  22.         used for I/O to arbitrary screen positions.
  23.  
  24.         The window is defined by a pair of coordinates specified on
  25.         the command line. The only absolute format requirements are
  26.         that each coordinate pair start with a left parenthesis and
  27.         be separated with a comma. Everything else is optional. The
  28.         suggested command format is:
  29.  
  30.         window (ur,lc) to (lr,rc)
  31.  
  32.         ur = upper row
  33.         lc = left column
  34.         lr = lower row
  35.         rc = right column
  36.  
  37.         The new functions serviced by the video interrupt (int 10)
  38.         and their corresponding function codes are:
  39.  
  40.         ah = 14 Write TTY
  41.         ah = 16 Set window coordinates
  42.         ah = 17 Get window coordinates
  43.         ah = 18 Get blanking attribute
  44.  
  45.         \
  46.  
  47. code        segment
  48.         org    100h                ;For COM conversion
  49.  
  50.         assume    cs:code
  51.  
  52. DOS_entry    label    far                ;DOS entry point
  53.         jmp    install
  54.  
  55. upper_left    label    word                ;Window coordinates
  56. left        db    0
  57. upper        db    0
  58. lower_right    label    word
  59. right        db    79
  60. lower        db    24
  61.  
  62. old_int        dd    ?                ;Old interrupt vector
  63.  
  64. comment        \
  65.  
  66.         The new interrupt procedure first filters out the new
  67.         services from the old, and passes all old service calls
  68.         back to the BIOS.
  69.  
  70.         \
  71.  
  72. interrupt    proc    far
  73.         sti
  74.         cmp    ah,14                ;Write TTY
  75.         je    write_tty
  76.         cmp    ah,16                ;Set window
  77.         je    set_window
  78.         cmp    ah,17                ;Get window
  79.         je    get_window
  80.         cmp    ah,18                ;Get blanking
  81.         je    get_blanking
  82. bios:        jmp    old_int
  83.  
  84. comment        \
  85.  
  86.         Set window coordinates.
  87.  
  88.         This function call sets the coordinates of a window in the
  89.         display area. The window is defined by specifying the upper
  90.         left and lower right corners in terms of screen coordinates.
  91.         The upper left corner of the screen is position (0,0). The
  92.         specified corners are included in the window area.
  93.  
  94.         If the specified coordinates are legal then the window is
  95.         cleared, the cursor is homed to the upper left corner, and
  96.         al = 0. Otherwise, no action is taken and al = 1.
  97.  
  98.         Entry:    ah = 16 (function code)
  99.             cx = upper left corner
  100.             dx = lower right corner
  101.         Exit:    al = fail flag (see above)
  102.  
  103.         All registers preserved except ax.
  104.  
  105.         \
  106.  
  107. set_window:    push    bx                ;Save registers
  108.         push    cx
  109.         push    dx
  110.         mov    al,1
  111.         cmp    ch,dh                ;Check coordinates
  112.         ja    exit
  113.         cmp    cl,dl
  114.         ja    exit
  115.         mov    upper_left,cx            ;Update coordinates
  116.         mov    lower_right,dx
  117.         mov    ah,18                ;Read blank attribute
  118.         int    10h
  119.         mov    ax,600h                ;Blank entire window
  120.         int    10h
  121.         mov    ah,15                ;Read current page
  122.         int    10h
  123.         mov    dx,cx                ;Home cursor
  124.         mov    ah,2
  125.         int    10h
  126.         mov    al,0
  127. exit:        pop    dx                ;Restore registers
  128.         pop    cx
  129.         pop    bx
  130.         iret
  131.  
  132. comment        \
  133.  
  134.         Get window coordinates.
  135.  
  136.         This function call returns the coordinates of the upper left
  137.         and lower right corners of the current display window.
  138.  
  139.         Entry:    ah = 17 (function code)
  140.         Exit:    cx = upper left corner
  141.             dx = lower right corner
  142.  
  143.         All registers preserved except cx and dx.
  144.  
  145.         \
  146.  
  147. get_window:    mov    cx,upper_left            ;Read coordinates
  148.         mov    dx,lower_right
  149.         iret
  150.  
  151. comment        \
  152.  
  153.         Get blanking attribute.
  154.  
  155.         This function call returns the attribute of the character
  156.         at the current cursor position, if in alpha mode, or the
  157.         background color (0) if in graphics mode. The resulting
  158.         attribute is meant to be used when scrolling the screen.
  159.  
  160.         Entry:    ah = 18 (function code)
  161.         Exit:    bh = blanking attribute
  162.  
  163.         All registers preserved except bx.
  164.  
  165.         \
  166.  
  167. get_blanking:    push    ax                ;Save registers
  168.         mov    ah,15                ;Read current page
  169.         int    10h
  170.         xor    ah,ah                ;Background color
  171.         cmp    al,3                ;Check for alpha modes
  172.         jbe    alpha
  173.         cmp    al,6                ;Check for graphics
  174.         jbe    graphics
  175. alpha:        mov    ah,8                ;Read attribute
  176.         int    10h
  177. graphics:    mov    bh,ah                ;Return attribute
  178.         pop    ax
  179.         iret
  180.  
  181. comment        \
  182.  
  183.         Write TTY.
  184.  
  185.         This function call replaces the old call of the same name.
  186.         It performs the same functions but allows the current window
  187.         to be user defined instead of the whole screen.
  188.  
  189.         Entry:    ah = 14 (function code)
  190.             al = character to write
  191.             bh = page number to write on
  192.             bl = foreground color (in graphics modes)
  193.  
  194.         All registers preserved.
  195.  
  196.         \
  197.  
  198. write_tty:    cmp    al,7                ;Let BIOS ring the bell
  199.         je    bios
  200.         push    ax                ;Save registers
  201.         push    bx
  202.         push    cx
  203.         push    dx
  204.         push    ax                ;Save character
  205.         mov    ah,3                ;Read cursor position
  206.         int    10h
  207.         pop    ax                ;Recover character
  208.  
  209. ;        Check for unprintable control characters
  210.  
  211.         cmp    al,8                ;Backspace
  212.         je    bs
  213.         cmp    al,10                ;Line feed
  214.         je    lf
  215.         cmp    al,13                ;Carriage return
  216.         je    cr
  217.  
  218. ;        Character is printable
  219.  
  220.         mov    cx,1                ;Print character
  221.         mov    ah,10
  222.         int    10h
  223.         inc    dl                ;Advance cursor
  224.         cmp    dl,right
  225.         jbe    set_cursor
  226.  
  227. ;        Right edge of window exceeded - wrap to next line
  228.  
  229.         mov    dl,left
  230. lf:        inc    dh
  231.         cmp    dh,lower
  232.         jbe    set_cursor
  233.  
  234. ;        Lower edge of window exceeded - scroll window up
  235.  
  236.         push    bx                ;Save page
  237.         mov    ah,18                ;Read blank attribute
  238.         int    10h
  239.         mov    cx,upper_left            ;Scroll window up
  240.         mov    dx,lower_right
  241.         mov    ax,601h
  242.         int    10h
  243.         pop    bx                ;Restore page
  244.  
  245. ;        Return cursor to left-hand edge
  246.  
  247. cr:        mov    dl,left                ;Carriage return
  248.  
  249. ;        Set cursor to new position
  250.  
  251. set_cursor:    mov    ah,2                ;Set cursor
  252.         int    10h
  253.         pop    dx                ;Restore registers
  254.         pop    cx
  255.         pop    bx
  256.         pop    ax
  257.         iret
  258.  
  259. ;        Backspace does not wrap past left edge of window
  260.  
  261. bs:        dec    dl                ;Back up
  262.         cmp    dl,left                ;Past left edge?
  263.         jb    cr                ;Yes, reset cursor
  264.         jmp    set_cursor            ;No, leave it alone
  265.  
  266. interrupt    endp
  267.  
  268. greeting    db    13,10
  269.         db    218,30 dup (196),191,13,10
  270.         db    179,' The Graphic Software Company ',179,13,10
  271.         db    179,'  BIOS Window Extension V1.1  ',179,13,10
  272.         db    192,30 dup (196),217,13,10,'$'
  273.  
  274. error_msg    db    13,10,'Invalid window coordinates',13,10,'$'
  275.  
  276. comment        \
  277.  
  278.         The install procedure is invoked through the DOS entry point
  279.         when the program is first run. It installs the new interrupt
  280.         and prints a message on the console. When done, it returns to
  281.         DOS and allows the space it occupies itself to be reclaimed.
  282.  
  283.         The program first tests whether the BIOS extensions are already
  284.         installed. If they are not, this can be detected by the fact
  285.         that a call to an illegal function will return without altering
  286.         any registers.
  287.  
  288.         \
  289.  
  290.         assume    ds:code
  291.  
  292. install        proc    near
  293.         mov    ah,17                ;Read coordinates
  294.         int    10h
  295.         inc    cl                ;Alter their value
  296.         mov    al,cl
  297.         int    10h                ;Read them again
  298.         cmp    al,cl                ;Test for difference
  299.         pushf
  300.         jne    installed
  301.  
  302. ;        Install BIOS extensions
  303.  
  304.         mov    dx,offset greeting        ;Report installation
  305.         mov    ah,9
  306.         int    21h
  307.         mov    ax,3510h            ;Read old interrupt
  308.         int    21h
  309.         mov    old_int,bx            ;Save old interrupt
  310.         mov    old_int+2,es
  311.         mov    dx,offset interrupt        ;Install new interrupt
  312.         mov    ax,2510h
  313.         int    21h
  314.  
  315. ;        BIOS extensions are installed now
  316.  
  317. installed:    push    cs                ;Point to command tail
  318.         pop    es
  319.         mov    di,81h
  320.         mov    cx,7fh                ;Read coordinates
  321.         mov    al,'('
  322.         repne    scasb                ;Find first pair
  323.         call    num_pair
  324.         push    dx
  325.         repne    scasb                ;Find second pair
  326.         call    num_pair
  327.         pop    cx
  328.         mov    ah,16                ;Set coordinates
  329.         int    10h
  330.         or    al,al                ;Test legality
  331.         jz    legal
  332.  
  333. ;        Window coordinates are illegal
  334.  
  335.         mov    dx,offset error_msg        ;Print error message
  336.         mov    ah,9
  337.         int    21h
  338.  
  339. ;        Terminate program in appropriate manner
  340.  
  341. legal:        popf                    ;Check residency
  342.         jne    resident
  343.         mov    dx,offset greeting        ;Make resident
  344.         int    27h
  345.  
  346. resident:    int    20h                ;Already resident
  347.  
  348. num_pair    proc    near
  349.         push    bx
  350.         call    number                ;Read first number
  351.         mov    bh,dl
  352.         call    number                ;Read second number
  353.         mov    dh,bh
  354.         pop    bx
  355.         ret                    ;Row/Col pair in dx
  356. num_pair    endp
  357.  
  358. number        proc    near